/**
 * @ClassName Offer27
 * @Description 剑指 Offer 27. 二叉树的镜像
 * @Author clockTown
 * @Date 2021/8/18 9:08
 * @Version 1.0
 */
class Offer27 {
}

/**
 * v0 递归
 */
class Offer27V0 {
    public TreeNode mirrorTree(TreeNode root) {
        if (root == null){
            return null;
        }
        //先使用递归保证左右子树转换为镜像子树
        TreeNode leftNode = mirrorTree(root.left);
        TreeNode rightNode = mirrorTree(root.right);
        // 交换节点的左右子树
        root.left = rightNode;
        root.right = leftNode;
        return root;
    }
}